package com.newy.dao.misc;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.newy.core.hibernate.HibernateDao;
import com.newy.domain.misc.FqaPost;
import com.newy.domain.misc.FqaType;

/**
 * 
 * @author linzongxue 2012-2-19
 *
 */
@Repository
public class FqaPostDao extends HibernateDao<FqaPost, Long> {
	/**
	 * 计算指定FQA类型所包含的FQA内容记录的总数
	 */
	public long getCountOfType(Long typeId){
		return this.countResult(Restrictions.eq("typeId", typeId));
	}
	
	public List<FqaPost> getAllOfType(FqaType type){
		String hql = "select post from FqaPost post, FqaType type where post.typeId=type.id and (type.id = ? or type.parentIdPath like ?) order by type.parentIdPath";
		return this.find(hql, type.getId(), type.getParentIdPath() + type.getId() + "/%");
	}
}
